import instacne from "../request";
import type { Ref } from "vue"

interface IGoodsListParams {
    id?: number | Ref<string>
    parentId?: string | Ref<string>
    keyword?: string | Ref<string>;
    pageNum?: number | Ref<number>;
    pageSize?: number | Ref<number>;
}

interface IGoodsfenleiListItem {
    description: string;
    icon: string;
    id: number;
    keywords: string;
    level: number;
    name: string;
    navStatus: number;
    parentId: number;
    productCount: number;
    productUnit: string;
    showStatus: number;
    sort: number;
}

interface IGoodsfenleiListRes {
    [x: string]: any;
    list: IGoodsfenleiListItem[];
    productAttributeList: any[]
    name: string
    pageNum: number;
    pageSize: number;
    total: number;
    totalPage: number;
}
interface IupdatenavParams {
    ids?: number | number[];
    navStatus?: number;
    showStatus?: number

}
//添加分类接口
interface IaddproductCategory {
    description?: string;
    icon?: string;
    keywords?: string;
    name: string;
    navStatus?: number;
    parentId?: number;
    productAttributeIdList?: number | number[],
    productUnit?: string;
    showStatus?: number;
    sort?: number;
}
//品牌显示隐场参数
interface IupdateFactoryStatus {
    newStatus?:number;
    publishStatus?:number;
    recommendStatus?:number;
    factoryStatus?: number | number[];
    showStatus?: number | number[];
    ids: number | number[]
}
//所有商品请求的类型接口
interface IProductListParams {
    keyword?: string | string[];
    productSn?: string | string[];
    productCategoryId?: number;
    brandId?: number;
    publishStatus?: number;
    verifyStatus?: null
    pageNum?: number;
    pageSize?: number;
}
//所有商品响应的数据类型接口
interface IIProductListItem {
    albumPics: string;
    brandId: number,
    brandName: string;
    deleteStatus: number;
    description: string;
    detailDesc: string;
    detailHtml: string;
    detailMobileHtml: string;
    detailTitle: string;
    feightTemplateId: number;
    giftGrowth: number;
    giftPoint: number;
    id: number;
    keywords: string;
    lowStock: number;
    name: string;
    newStatus: number;
    note: string;
    originalPrice: number;
    pic: string;
    previewStatus: number;
    price: number,
    productAttributeCategoryId: number;
    productCategoryId: number;
    productCategoryName: string;
    productSn: string;
    promotionEndTime: string;
    promotionPerLimit: number;
    promotionPrice: number;
    promotionStartTime: string;
    promotionType: number;
    publishStatus: number;
    recommandStatus: number;
    sale: number;
    serviceIds: string;
    sort: number;
    stock: number;
    subTitle: string;
    unit: string;
    usePointLimit: number;
    verifyStatus: number;
    weight: number;
}
interface IProductList {
    list: IIProductListItem[],
    pageNum: number;
    pageSize: number
    total: number;
    totalPage: number;
}
//所有商品一级分类 productCategory/list/withChildren
const GoodsfenleiList = (data: IGoodsListParams): Promise<IGoodsfenleiListRes> => {
    return instacne.get(`productCategory/list/${data.parentId ? data.parentId : 0}`, {
        params: data,
    })
}
//品牌列表 /brand/list
const GoodsBrandList = (data: IGoodsListParams): Promise<IGoodsfenleiListRes> => {
    return instacne.get('/brand/list', {
        params: data,
    })
}
// productAttribute/category/list分页获取所有商品属性分类
const GoodscategoryList = (data: IGoodsListParams): Promise<IGoodsfenleiListRes> => {
    return instacne.get('productAttribute/category/list', {
        params: data,
    })
}
//筛选属性接口 productAttribute/category/list/withAttr
const GoodswithAttrList = (): Promise<IGoodsfenleiListRes[]> => {
    return instacne.get('productAttribute/category/list/withAttr')
}
//productCategory/delete/{id}删除商品分类
const GoodsDletefenleiList = (data: IGoodsListParams) => {
    return instacne.post(`productCategory/delete/${data.id}`)
}
//brand/delete/{id}删除品牌
const GoodsDleteBrandList = (data: IGoodsListParams) => {
    return instacne.get(`brand/delete/${data.id}`)
}
//productAttribute/category/delete/id 删除属性
const GoodsDletecategoryList = (data: IGoodsListParams) => {
    return instacne.get(`productAttribute/category/delete/${data.id}`)
}
//productCategory/list/withChildren所有一级分类及其子类
const GoodswithChildrenList = () => {
    return instacne.get('productCategory/list/withChildren')
}
// productCategory/update/navStatus 商品分类的显示隐藏ids: 94 navStatus: 0
const updatenavStatus = (data: IupdatenavParams) => {
    return instacne.post(`productCategory/update/navStatus?ids=${data.ids}&navStatus=${data.navStatus}`)
}
// productCategory/update/showStatus修改显示状态
const updatenavShowStatus = (data: IupdatenavParams) => {
    return instacne.post(`productCategory/update/showStatus?ids=${data.ids}&showStatus=${data.showStatus}`)
}
//productCategory/create添加产品分类
const addproductCategory = (data: IaddproductCategory) => {
    return instacne.post(`productCategory/create`, data)
}
//brand/update/factoryStatus批量更新厂家制造商状态
const updateFactoryStatus = (data: IupdateFactoryStatus) => {
    return instacne.post(`brand/update/factoryStatus?ids=${data.ids}&factoryStatus=${data.factoryStatus}`)
}
//brand/update/showStatus批量更新显示状态
const brandupdateshowStatus = (data: IupdateFactoryStatus) => {
    return instacne.post(`brand/update/showStatus?ids=${data.ids}&showStatus=${data.showStatus}`)
}
//product/list查询商品
const ProductList = (data: IProductListParams): Promise<IProductList> => {
    return instacne.get('product/list', {
        params: data
    })
}
//删除商品product/update/deleteStatus?ids=1337&deleteStatus=1
const DeleteProduct = (data: IupdatenavParams) => {
    return instacne.post(`product/update/deleteStatus?ids=${data.ids}&deleteStatus=1`)
}
//修改上架状态product/update/publishStatus
const UpdatePublishStatus = (data: IupdateFactoryStatus) =>{
    return instacne.post(`product/update/publishStatus?ids=${data.ids}&publishStatus=${data.showStatus }`)
}
//修改新品状态product/update/newStatus批量设为新品
const UpdatenewStatus = (data: IupdateFactoryStatus) =>{
    return instacne.post(`product/update/newStatus?ids=${data.ids}&newStatus=${data.showStatus }`)
}
//product/update/recommendStatus批量推荐商品
const UpdaterecommendStatus = (data: IupdateFactoryStatus) =>{
    return instacne.post(`product/update/recommendStatus?ids=${data.ids}&recommendStatus=${data.showStatus }`)
}
export {
    GoodsfenleiList, GoodsBrandList, GoodscategoryList, GoodswithAttrList,
    GoodsDletefenleiList, GoodsDleteBrandList, GoodsDletecategoryList, GoodswithChildrenList
    , updatenavStatus, updatenavShowStatus, addproductCategory, updateFactoryStatus,
    brandupdateshowStatus, ProductList, DeleteProduct,UpdatePublishStatus,UpdatenewStatus,
    UpdaterecommendStatus
}
export type { IGoodsListParams,IProductListParams }

// 获取商品列表数据


